﻿using CLManagement;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataFileApp
{
    public class Operate
    {
        public static string jsonPath;
        public Operate(string path)
        {
            jsonPath = path;
        }

        static Management management;
        /// <summary>
        /// 从本地路径加载json文件
        /// </summary>
        /// <param name="path"></param>
        public static string LoadJsonFromFile(string path)
        {
            management = new Management();
            var jsonStr = management.LoadJsonFromFile(path);
            return jsonStr.ToString();
        }

        /// <summary>
        /// 另存为
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <param name="path"></param>
        public static void SaveJsonToFile(string path)
        {

            var jsonStr = management.LoadJsonFromFile(path);
            management.SaveJsonToFile(jsonStr, path);
        }

        /// <summary>
        /// 在json指定节点下添加数据，数据可能为json中的 {} / [] / 键值对
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="objectStr"></param>
        public static void AddKeyValue(string keyName, JToken value)
        {
            management.AddKeyValue(keyName, value);

        }

        /// <summary>
        /// 修改json节点下指定键值对的值
        /// </summary>
        /// <param name="keyName"></param>
        /// <param name="value"></param>
        public static void ModifyValue(string keyName, JToken value)
        {
            management.ModifyValue(keyName, value);
        }

        /// <summary>
        /// 修改json节点下指定键值对的键
        /// </summary>
        /// <param name="keyName"></param>
        /// <param name="value"></param>
        public static void ModifyKeyName(string oldKeyName, string newKeyName)
        {
            management.ModifyKeyName(oldKeyName, newKeyName);
        }

        /// <summary>
        /// 删除json节点下指定的键值对
        /// </summary>
        /// <param name="keyName"></param>
        /// <param name="value"></param>
        public static void Delete(string KeyName)
        {
            management.Delete(KeyName);
        }



        public static void copyKeyAtSameLevelWithNewName(string keyName, string newKeyName)
        {
            management.copyKeyAtSameLevelWithNewName(keyName, newKeyName);

        }

        public static void AddKeyValueClass(string keyName)
        {
            management.AddKeyValueClass(keyName);
        }
        public static void AddJobject(string Comments, string keyName, JObject keyValuePairs)
        {
            management.AddJobject(Comments, keyName, keyValuePairs);
        }


        public static string GetComments(string Comments, string keyName, string lang)
        {
            string data;

            data = management.GetComments(Comments, keyName, lang);

            return data;
        }


        public static T GetValue<T>(string keyName)
        {
            return management.GetValue<T>(keyName);
        }

    }
}
